package com.cuz.daileetcode.位运算;

import com.cuz.daileetcode.utils.ArrayUtils;

/***
 * 不使用任何变量交换两个整数
 */
public class SwapTowNumWithoutVariable {

    public static void swap(int[]towNum){
        towNum[0]=towNum[0]^towNum[1];
        towNum[1]=towNum[0]^towNum[1];
        towNum[0]=towNum[0]^towNum[1];
    }

    public static void main(String[] args) {
        int[] num = {1, 2};
        swap(num);
        ArrayUtils.print(num);
        System.out.println(Integer.toBinaryString(-1));
        System.out.println(Integer.toBinaryString((-1 >> 31)));
        System.out.println(Integer.toBinaryString(1));
        System.out.println((-1 >> 31)&1);
    }
}
